package com.rabbitmq.service;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SendService {
    //AMQP的模板工具接口,可以利用这个接口我们可以对AMQP做任何事情(发送和接收消息)
    @Resource
    private AmqpTemplate amqpTemplate;
    //RabbitMQ的模板工具类,它是AmqpTemplate的子类我们可以利用这个类完成对RabbitMQ的基本操作例如发送接收以及事务等等
    @Resource
    private RabbitTemplate rabbitTemplate;

    public void directSend(String message){

        amqpTemplate.convertAndSend("bootDirect","bootKey",message);
    }
    public void fanoutSend(String message){
        amqpTemplate.convertAndSend("fanoutBootExchange","",message);
    }
    public void topicSend(String message,String routingKey){
        amqpTemplate.convertAndSend("topicBootExchange",routingKey,message);
    }

}
